//Appears before the boss

script_enemy_main{

let GRenemy=("\script\Images\Enemies\Fairy3-15.png");
let SEshot1=("script\SoundEffects\shotm1.wav");
let SEshot2=("script\SoundEffects\shots6.wav");
let SEdeath=("script\SoundEffects\enemydeath1.wav");
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;
let startx=GetX; let starty=GetY;
let frame=0; let time=0; let animation=0;
let ani=6;
let scale=0.75;
let shots=0;
let shotcolor=0; let shotspeed=0;
let oldX=0; let oldY=0;
let invincible=125;

let timedout=0;
let angle=rand(0,360);
SetAngle(90);
SetSpeed(4);

@Initialize{
	LoadGraphic("\script\Images\Enemies\Fairy3-15.png");
	LoadSE("script\SoundEffects\shotm1.wav");
	LoadSE("script\SoundEffects\shots6.wav");

	SetInvincibility(120);
	SetLife(70);
	SetDamageRate(10,3); 
	SetScore(1000);
	SetShotColor(255,255,255);
}

@MainLoop{

if(GetX<=minx-32 || GetX>=maxx+32 || GetY<=miny-32 || GetY>=maxy+32 && frame>=60){ VanishEnemy; }

if((GetX>minx && GetX<maxx) && (GetY>miny && GetY<maxy)){
SetCollisionA(GetX,GetY,32*scale);
SetCollisionB(GetX,GetY,32*scale);

if(GetCommonData("Difficulty")==1){
	if(time%20==0 && time>=90){
	let shot1=0;
		loop(4){
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,3,angle,0,-0.06,0,51);
		SetShotDataA(shot1,90,0,angle,0,0.03,3,51);
		FireShot(shot1);
		angle+=360/4;
		}
	angle+=10;
	PlaySE(SEshot1);
	}
	if(time%50==0 && time>=90){
		loop(10){
		CreateShot01(GetX,GetY,2,angle,61,0);
		angle+=360/10;
		}
	PlaySE(SEshot2);
	}
} //Easy

//=================================================

if(GetCommonData("Difficulty")==2){
	if(time%15==0 && time>=90){
	let shot1=0;
	let shot2=1;
		loop(4){
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,4,angle,0,-0.06,0,51);
		SetShotDataA(shot1,90,0,angle+20,0,0.03,5,50);
			CreateShotA(shot2,0,0,0);
			SetShotDataA(shot2,0,0,angle-20,0,0.03,5,51);
			AddShot(90,shot1,shot2,0);
		FireShot(shot1);
		angle+=360/4;
		}
	angle+=10;
	PlaySE(SEshot1);
	}
	if(time%50==0 && time>=90){
		loop(20){
		CreateShot01(GetX,GetY,2.5,angle,61,0);
		angle+=360/20;
		}
	PlaySE(SEshot2);
	}
} //Normal

//=================================================

if(GetCommonData("Difficulty")==3){
	if(time%10==0 && time>=90){
	let shot1=0;
	let shot2=1;
		loop(6){
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,4,angle,0,-0.06,0,51);
		SetShotDataA(shot1,90,0,angle,0.3,0.03,5,50);
			CreateShotA(shot2,0,0,0);
			SetShotDataA(shot2,0,0,angle,-0.3,0.03,5,51);
			AddShot(90,shot1,shot2,0);
		FireShot(shot1);
		angle+=360/6;
		}
	angle+=10;
	PlaySE(SEshot2);
	}
	if(time%50==0 && time>=90){
		loop(25){
		CreateShot01(GetX,GetY,3,angle,61,0);
		angle+=360/25;
		}
	PlaySE(SEshot1);
	}
} //Hard

//=================================================

if(GetCommonData("Difficulty")==4){
	if(time%5==0 && time>=90){
	let shot1=0;
	let shot2=1;
		loop(8){
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,4,angle,0,-0.06,0,51);
		SetShotDataA(shot1,90,0,angle,0.3,0.03,5,50);
			CreateShotA(shot2,0,0,0);
			SetShotDataA(shot2,0,0,angle,-0.3,0.03,5,51);
			AddShot(90,shot1,shot2,0);
		FireShot(shot1);
		angle+=360/8;
		}
	angle+=10;
	PlaySE(SEshot2);
	}
	if(time%50==0 && time>=90){
		loop(30){
		CreateShot01(GetX,GetY,3,angle,61,0);
		angle+=360/30;
		}
	PlaySE(SEshot1);
	}
} //Lunatic
} //Onscreen


if(time<90){ SetSpeed(GetSpeed-(4/90)); }
if(time==45){ SetColor(255,255,128); Concentration01(60); SetColor(255,255,255); }
if(time==600){ SetLife(0); timedout=1; }




oldX=GetX;
oldY=GetY;
frame++;
time++;
animation++;
if(animation>=ani*6){ animation=0; }
if(GetTimeOfInvincibility<25 && invincible>0){ invincible=GetTimeOfInvincibility*5; }

}

@DrawLoop{
let side=0;
	SetTexture(GRenemy);
		if(oldX<GetX || oldX>GetX){ side=128; }
		if(animation>=ani*0 && animation<ani*1){ SetGraphicRect(1,side,256,128+side); }
		if(animation>=ani*1 && animation<ani*2){ SetGraphicRect(257,side,512,128+side); }
		if(animation>=ani*2 && animation<ani*3){ SetGraphicRect(513,side,768,128+side); }
		if(animation>=ani*3 && animation<ani*4){ SetGraphicRect(769,side,1024,128+side); }
		if(animation>=ani*4 && animation<ani*5){ SetGraphicRect(513,side,768,128+side); }
		if(animation>=ani*5 && animation<ani*6){ SetGraphicRect(257,side,512,128+side); }
	SetGraphicAngle(0,0,0);
	if(oldX<GetX){ SetGraphicAngle(180,0,0); }
	SetGraphicScale(scale,scale);
	SetColor(255-invincible,255-invincible,255);
	DrawGraphic(GetX,GetY);
}

@Finalize{
if(BeVanished==false){
PlaySE(SEdeath);
	if(timedout==0){
	let itemangle=0;
		loop(10){
		CreateEnemyFromFile("script\Functions\itempoint.txt",GetX+30*cos(itemangle),GetY+30*sin(itemangle),0,0,0);
		itemangle+=360/10;
		}
	CreateEnemyFromFile("script\Functions\itembigpower.txt",GetX,GetY,0,0,0);
	}
}
SetCommonData("IncreasePhase",1);
}

}